<?php

use App\Http\Controllers\Admin\CurdController;
use Illuminate\Support\Facades\Route;

/*
需要权限管理路由必须有名称, 使用 Route::apiResource 或 Route::resource 方法会自动添加路由名称, 无需人工干预;
对应的翻译文件在 lang/$language/routes.php
*/

function addCurdRoute(string $name)
{
    Route::addRoute("GET", $name, [CurdController::class, "index"])->name("{$name}.index");
    Route::addRoute("POST", $name, [CurdController::class, "store"])->name("{$name}.store");
    Route::addRoute("PUT", "{$name}/{id}", [CurdController::class, "update"])->where('id', '\d+')->name("{$name}.update");
    Route::addRoute("PUT", "{$name}/easy/{id}", [CurdController::class, "easyUpdate"])->where('id', '\d+')->name("{$name}.easyUpdate");
    Route::addRoute("DELETE", "{$name}/{id}", [CurdController::class, "destroy"])->where('id', '\d+')->name("{$name}.destroy");
    Route::addRoute("DELETE", "{$name}/multiple", [CurdController::class, "destroyMultiple"])->name("{$name}.multipleDestroy");
}


Route::domain(config('admin.domain'))->group(function () {
    Route::any('/', 'IndexController@index')->name('index');
    Route::prefix('login')->group(function() {
        Route::get('qrcode', 'LoginController@getQrcode');
        Route::get('qrcode-query', 'LoginController@qrcodeQuery');
        Route::post('', 'LoginController@authenticate')->name('login');
        Route::post('sms-code', 'LoginController@sendCode')->middleware('throttle:20,1');
    });

    Route::prefix('api')->middleware('auth:admin')->group(function () {

        Route::post('upload', 'UploadController@store');
        Route::get('my-menu', 'IndexController@menu');
        Route::get('dashboard', 'IndexController@dashboard');
        Route::get('dash-count', 'IndexController@dashCount');
        Route::get('all/{modelName}', 'IndexController@all');
        Route::any('quick-set', 'IndexController@quickSet')->name('index.quickSet');
        Route::get('download-config/{name}', 'IndexController@downloadConfig')->name('index.downloadConfig');


        Route::prefix('manager')->group(function () {
            Route::get('info', 'ManagerController@info')->name('manager.info');
            Route::get('logout', 'ManagerController@logout');
            Route::get('bind-qrcode', 'ManagerController@getBindQrcode');
            Route::get('bind-query', 'ManagerController@bindQuery');
            Route::put('simple', 'ManagerController@updateSimple');
            Route::get('role-access/format', 'RoleAccessController@format')->name('role-access.format');
            Route::apiResource('role-access', 'RoleAccessController');

            Route::apiResource('role', 'RoleController');
            Route::apiResource('logs','ManagerLogController');
        });

        Route::apiResource('manager', 'ManagerController');
        Route::apiResource('menu', 'MenuController');

        // 渠道
        Route::apiResource('app-source', 'AppSourceController');
        // 应用版本
        Route::prefix('app-version')->name('app-version.')->group(function() {
            Route::put('batch', 'AppVersionController@batch')->name('batch');
        });
        Route::apiResource('app-version', 'AppVersionController');
        // 应用资源
        Route::apiResource('app-resource', 'AppResourceController');
        // 应用APPID
        Route::prefix('app-appid')->name('app-appid.')->group(function () {
            Route::put('batch', 'AppAppidController@batch')->name('batch');
        });
        Route::apiResource('app-appid', 'AppAppidController');
        // 应用网页
        Route::apiResource('app-webpage', 'AppWebpageController');
        // 短信签名
        Route::apiResource('sms-sign', 'SmsSignController');
        // uuid白名单
        Route::apiResource('uuid-white-list', 'UuidWhiteListController');

        // 推广数据
        Route::prefix('spread-data')->name('spread-data.')->group(function() {
            Route::get('day-stat', 'SpreadDataController@dayStat')->name('dayStat');
            Route::get('daily', 'SpreadDataController@daily')->name('daily');
            Route::get('daily-agent', 'SpreadDataController@dailyAgent')->name('dailyAgent');
            Route::get('daily-agent-sub', 'SpreadDataController@dailyAgentSub')->name('dailyAgentSub');
            Route::get('daily-agent-reg', 'SpreadDataController@dailyAgentReg')->name('dailyAgentReg');
            Route::get('daily-agent-reg-2-active', 'SpreadDataController@dailyAgentReg2Active')->name('dailyAgentReg2Active');
            Route::put('daily-simple/{id}', 'SpreadDataController@dailySimpleUpdate')->name('dailySimpleUpdate');
            Route::put('daily-batch', 'SpreadDataController@dailyBatchUpdate')->name('dailyBatchUpdate');
            Route::get('daily-all', 'SpreadDataController@dailyAll')->name('dailyAll');
            Route::get('month', 'SpreadDataController@month')->name('month');
            Route::put('month-simple/{id}', 'SpreadDataController@monthSimpleUpdate')->name('monthSimpleUpdate');
            Route::put('month-batch', 'SpreadDataController@monthBatchUpdate')->name('monthBatchUpdate');
            Route::get('month-all', 'SpreadDataController@monthAll')->name('monthAll');
            Route::get('source-ltv', 'SpreadDataController@sourceLtv')->name('sourceLtv');
            Route::get('source-ltv-detail', 'SpreadDataController@sourceLtvDetail');
            Route::get('source-ltv-roi', 'SpreadDataController@sourceLtvRoi');
            Route::get('source-ltv-roi-chart', 'SpreadDataController@sourceLtvRoiChart');
            Route::get('hour', 'SpreadDataController@hour')->name('hour');
            Route::get('hour-simple', 'SpreadDataController@hourSimple')->name('hourSimple');
        });

        // 渠道方案
        Route::apiResource('app-source-config', 'AppSourceConfigController');
        // APK 管理
        Route::prefix('apk')->name('apk.')->group(function() {
            Route::put('batch', 'ApkController@batch')->name('batch');
            Route::get('base', 'ApkController@base');
            Route::post('base', 'ApkController@uploadBase');
            Route::delete('base/{name}', 'ApkController@deleteBase');
        });

        Route::apiResource('apk', 'ApkController');

        // 渠道 CPA关联
        Route::prefix('app-source-cpa')->group(function() {
            Route::get('configs', 'AppSourceCpaController@configs');
            Route::get('day-cpa-cost', 'AppSourceCpaController@dayCpaCost');
            Route::get('advertiser-ids', 'AppSourceCpaController@advertiserIds');
        });
        Route::apiResource('app-source-cpa', 'AppSourceCpaController');
        // 应用大事件
        Route::apiResource('app-news', 'AppNewsController');
    });
});
